<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			html,body{
				width: 100%;
				height: 100%;
				background:url(images/timg.jpg);
				background-size: 100% 100%;
			}
			.container{
				width: 100%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		</style>
		<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
	</head>
	<body>
		<div class="container">
			<div style="width: 40rem;height: 40rem; background-color: rgba(255, 255, 255, 0.8);" id="">
				<h1 style="margin-left: 23%;">宿舍管理系统</h1>
				<br><br>
				<form action="" method="">
					<div style="transform: translate(5%);" id="form">
						<div class="input-group input-group-lg">
						  <span class="input-group-addon" id="sizing-addon1">@</span>
						  <input style="width: 85%;" type="text" name="user" class="form-control" placeholder="Username" aria-describedby="sizing-addon1">
						</div>
						<br>
						<div class="input-group input-group-lg">
						  <span class="input-group-addon" id="sizing-addon1">#</span>
						  <input  style="width: 85%;"  type="password" name="psd" class="form-control" placeholder="Password" aria-describedby="sizing-addon1">
						</div>
						<br>
						<input type="radio" name="radio" id="radio1" value="" />
						<span style="font-size: 20px;" id="">系统管理员</span>
						<input style="margin-left: 5%;" type="radio" name="radio" id="radio2" value="" />
						<span style="font-size: 20px;" id="">宿舍管理员</span>
						<input style="margin-left: 5%;"  type="radio" name="radio" id="radio3" value="" />
						<span style="font-size: 20px;" id="">学生</span>
						<br><br>
						<input type="checkbox" name="remember" id="" value="" />
						<span style="font-size: 20px;" id="">记住密码</span>
						<br><br>
						<button style="width: 43%;font-size: 20px;" type="button" class="btn btn-success" onclick="signIn()">登入</button>
						<button style="width: 43%;font-size: 20px;" type="button"  onclick="agin()" class="btn btn-warning">重置</button>
						<br><br>
						<button style="width: 87%;margin-top:2%;font-size: 20px;"  type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" onclick="registered()">注册</button>
						<!-- 模态框（Modal） -->
					</div>
				</form>
			</div>
		</div>
		<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//系统管理圆
			let arr = 
			[
				{id:1,user:"admin",psd:"123456"},
				{id:2,user:"3",psd:"333333"},
			];
			//学生
			let arr_stu=
			[
			]
			//接收学生数据
			let sign_stu = JSON.parse(localStorage.getItem("sign_stu"));
			if(sign_stu){
				arr_stu = sign_stu;
				console.log(sign_stu);
			}else{
				arr_stu = arr_stu;
				console.log(sign_stu)
			}
			//宿管
			let arr_su=
			[
			]
			let remember = [{user:"admin",psd:"123456"},];
			//接收宿管数据
			let sign_manager = JSON.parse(localStorage.getItem("sign_manager"));
			if(sign_manager){
				arr_su = sign_manager;
				console.log(arr_su);
			}else{
				arr_su = arr_su;
			}
			//接收注册后和修改后的数据
			let new_user = JSON.parse(localStorage.getItem("new_user"));
			console.log(new_user);
			console.log(arr_su);
			console.log(arr_stu);
			if(new_user){
				arr = new_user;
			}else{
				arr = arr;
			}
			//记住密码
			let data_remember = JSON.parse(localStorage.getItem("remember"));
			if(data_remember){
				remember = data_remember;
			}
			$("input[name='user']").change(function(){
				let name = $("input[name='user']").val();
				console.log($("input[name='user']").val());
				if($("#radio1").prop("checked")){
				for(index in remember){
					let item = remember[index];
					if(item.user === name){
						$("input[name='psd']").val(item.psd);
						break;
					}else{
						continue;
					}
				}
				}else if($("#radio2").prop("checked")){
					for(index in remember){
						let item = remember[index];
						if(item.user === name){
							$("input[name='psd']").val(item.psd);
							break;
						}else{
							continue;
						}
					}
				}else if($("#radio3").prop("checked")){
					for(index in remember){
						let item = remember[index];
						if(item.user === name){
							$("input[name='psd']").val(item.psd);
							break;
						}else{
							console.log("222")
							continue;
						}
					}
				}
			})
			//重置
			function agin(){
				$("input[name='user']").val("");
				$("input[name='psd']").val("");
			}
			//登入
			function signIn(){
				let user = $("input[name='user']").val();
				let psd = $("input[name='psd']").val();
				let user_data=
				{
					user:user,
					psd:psd,
				}
				let arr_remember =
				{
					user:user,
					psd:psd
				}
				if($("#radio1").prop("checked")){
				for(let index in arr){
						let item = arr[index];
						if(item.user === user && item.psd === psd){
							//传用户名密码
							//传用户名称
							localStorage.setItem("user_name",JSON.stringify(user_data));
							//传系统管理员的账号密码数据
							localStorage.setItem("manager",JSON.stringify(arr));
							//勾选记住密码存数据
							if($("input[name='remember']").prop("checked")){
								remember.push(arr_remember);
								localStorage.setItem("remember",JSON.stringify(remember));
							}
							window.location.href="manager.html";
							break;
						}
						continue;
					}
				}else if($("#radio2").prop("checked")){
					for(let index in arr_su){
						let item = arr_su[index];
						if(item.name === user && item.phone === psd){
							//传用户数据
							localStorage.setItem("stu_name",JSON.stringify(user_data));
							if($("input[name='remember']").prop("checked")){
								remember.push(arr_remember);
								localStorage.setItem("remember",JSON.stringify(remember));
							}
							localStorage.setItem("item",JSON.stringify(item));
							window.location.href="Dormitory.html";
							break;
						}
						continue;
					}
				}else if($("#radio3").prop("checked")){
					for(let index in arr_stu){
						let item = arr_stu[index];
						if(item.name === user && item.phone === psd){
							//传用户名称
							localStorage.setItem("s_name",JSON.stringify(user_data));
							if($("input[name='remember']").prop("checked")){
								remember.push(arr_remember);
								localStorage.setItem("remember",JSON.stringify(remember));
							}
							window.location.href="student.html";
							break;
						}
						continue;
					}
				}else{
					alert("账号或者密码错误");
				}
				
			}
			//注册
			function registered(){
				//将arr传给登入界面
				localStorage.setItem("arr_data",JSON.stringify(arr));
				window.location.href="registered.html";
				console.log($("#radio1").prop("checked"))
			}
		</script>
	</body>
</html>
